# frozen_string_literal: true

require_relative 'shell'

def git(url, path)
  path = shell.expand(path)

  if File.exist?(path)
    Dir.chdir(path) do
      remote_url = `git remote get-url origin`.strip
      if url == remote_url
        shell.exe 'git pull'
      else
        shell.exit 1, 'Git 仓库已存在，并且仓库内 url 与待克隆的 url 不一致'
      end
    end
  else
    shell.exe "git clone '#{url}' '#{path}'"
  end
end
